*****************************************************************************************
/* 	Analysis
	Technological Change Spanish survey
	Replication of Tables and Figures in Main text and Supporting Information
*/
*****************************************************************************************

use "gallego_etal_cps_tc_data.dta", clear

*****************************************************************************************

*Raw Table 1 (condensed) and Raw Table E1 (extended). Correlation of objective and subjective automation risks, ordered logit models

ologit tech_self_rs rti01 i.male i.age i.edu6c  
estimates store tech_self_rs1

ologit tech_self_rs rti01 i.male i.age i.edu6c i.employment i.income7c  i.ocupation
estimates store tech_self_rs1o

ologit tech_self_rs risk01 i.male i.age i.edu6c 
estimates store tech_self_rs2

ologit tech_self_rs risk01 i.male  i.age i.edu6c i.employment i.income7c  i.ocupation
estimates store tech_self_rs2o

esttab tech_self_rs1 tech_self_rs1o tech_self_rs2 tech_self_rs2o using T1andTE1.rtf, ///
	label se r2 b(%9.2f) t(%9.2f) r2(%9.2f) ///
	mtitle("RTI" "RTI" "Tasks" "Tasks") replace 


*****************************************************************************************

*Raw Table 2 (condensed) and Raw Tables F1 and F2 (extended). Correlation of objective and subjective risks with policy views, OLS estimations
 
foreach var in stoptech01 unemp01 expandsocial01 trade01{
reg `var' rti01 male i.age i.edu6c if exp1==1
estimates store `var'1
reg `var' rti01 male i.age i.edu6c i.employment i.income7c  i.ocupation if exp1==1
estimates store `var'2
reg `var' tech_self_rs01 male i.age i.edu6c i.employment i.income7c  i.ocupation if exp1==1
estimates store `var'3
reg `var' rti01 tech_self_rs01 male i.age i.edu6c i.employment i.income7c  i.ocupation if exp1==1
estimates store `var'4
}

esttab stoptech011 stoptech012 stoptech013 stoptech014 unemp011 unemp012 unemp013 unemp014 ///
	expandsocial011 expandsocial012 expandsocial013 expandsocial014 trade011 trade012 trade013 trade014 using T2andTF1.rtf, label se r2 b(%9.2f) t(%9.2f) r2(%9.2f) ///
	mtitle("Technology" "Technology" "Technology" "Technology" "Unemployment" "Unemployment" "Unemployment" "Unemployment" ///
	"Taxes" "Taxes" "Taxes" "Taxes") replace 
	
	
foreach var in stoptech01 unemp01 expandsocial01 trade01{
reg `var' risk01 male i.age i.edu6c if exp1==1
estimates store `var'1
reg `var' risk01 male i.age i.edu6c i.employment i.income7c  i.ocupation if exp1==1
estimates store `var'2
reg `var' tech_self_rs01 male i.age i.edu6c i.employment i.income7c  i.ocupation if exp1==1
estimates store `var'3
reg `var' risk01 tech_self_rs01 male i.age i.edu6c i.employment i.income7c  i.ocupation if exp1==1
estimates store `var'4
}
	
esttab stoptech011 stoptech012 stoptech013 stoptech014 unemp011 unemp012 unemp013 unemp014 ///
	expandsocial011 expandsocial012 expandsocial013 expandsocial014 trade011 trade012 trade013 trade014 using T2andTF2.rtf, label se r2 b(%9.2f) t(%9.2f) r2(%9.2f) ///
	mtitle("Technology" "Technology" "Technology" "Technology" "Unemployment" "Unemployment" "Unemployment" "Unemployment" ///
	"Taxes" "Taxes" "Taxes" "Taxes") replace
		
*****************************************************************************************

*Figure 1: Average effect of priming treatments and policy support
estimates clear
reg tecnologia b4.exp1
estimates store protech
reg unemp b4.exp1
estimates store unemp
reg expandsocial b4.exp1
estimates store expandsocial

coefplot 	(protech), 			bylabel(Slow down technology)  ///
			|| (unemp), 		bylabel(Unemployment benefits) 	///
			|| (expandsocial), 	bylabel(Expand social services) 	///
			||, drop(_cons) xline(0, lcolor(gs10)) base grid(none) ///
			byopts(xrescale graphregion(fcolor(white)) cols(3)) ///
			ylabel(, labsize(vlarge)) xlabel(, labsize(vlarge)) ///
			ysize(6) xsize(20) subtitle(, size(huge))

*Figure 2: Heterogeneous effects of the priming treatments 

*Technology (vs control)
interflex tecnologia techprime exp1_tech_prediction_rs, type(linear) ///
	ylab(tech. attitudes) dlab(tech.)  ///
	xlab(Pessimism about technology) ti(Slow down technology)
graph save Graph "fig1.gph", replace
	
interflex unemp techprime exp1_tech_prediction_rs, type(linear) ///
	ylab(unemployment) dlab(tech.)  ///
	xlab(Pessimism about technology) ti(Unemployment benefits)
graph save Graph "fig2.gph", replace

interflex expandsocial techprime exp1_tech_prediction_rs, type(linear) ///
	ylab(more services) dlab(tech.)  ///
	xlab(Pessimism about technology) ti(Expand social services) 
graph save Graph "fig3.gph", replace

graph combine "fig1" "fig2" "fig3", /// 
	col(3) imargin(3 3 3 3)  iscale(1) ysize(6) xsize(20)  	


*****************************************************************************************
*****************************************************************************************

*Appendix/Supporting information: 

*Appendix Table B1 - Descriptive statistics

sum tech_self rti01 risk income7c
tab age
tab edu6c
tab employment

*Appendix E1: see above

*Appendix F1-F2: see above

*Appendix G: Comparison to placebo

interflex tecnologia techprimeplacebo exp1_tech_prediction_rs, type(linear) ///
	ylab(tech. attitudes) dlab(tech.)  ///
	xlab(Pessimism about technology) ti(Slow down technology)
graph save Graph "fig1.gph", replace
	
interflex unemp techprimeplacebo exp1_tech_prediction_rs, type(linear) ///
	ylab(unemployment) dlab(tech.)  ///
	xlab(Pessimism about technology) ti(Unemployment benefits)
graph save Graph "fig2.gph", replace

interflex expandsocial techprimeplacebo exp1_tech_prediction_rs, type(linear) ///
	ylab(more services) dlab(tech.)  ///
	xlab(Pessimism about technology) ti(Expand social services) 
graph save Graph "fig3.gph", replace

graph combine "fig1" "fig2" "fig3", /// 
	col(3) imargin(3 3 3 3)  iscale(1) ysize(6) xsize(20)  
